﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Ninject;

namespace GigaSite.Domain.IoC
{
    /// <summary>
    /// Реализация резолвера зависимостей MVC для IoC контейнера Ninject
    /// </summary>
    public class NinjectDependencyResolver: IDependencyResolver
    {
        /// <summary>
        /// IoC контейнер для резолвинга
        /// </summary>
        public IKernel Container { get; private set; }

        /// <summary>
        /// Инициализирует IoС резолвер
        /// </summary>
        /// <param name="container"></param>
        public NinjectDependencyResolver(IKernel container)
        {
            Container = container;
        }

        /// <summary>
        /// Resolves singly registered services that support arbitrary object creation.
        /// </summary>
        /// <returns>
        /// The requested service or object.
        /// </returns>
        /// <param name="serviceType">The type of the requested service or object.</param>
        public object GetService(Type serviceType)
        {
            return Container.Get(serviceType);
        }

        /// <summary>
        /// Resolves multiply registered services.
        /// </summary>
        /// <returns>
        /// The requested services.
        /// </returns>
        /// <param name="serviceType">The type of the requested services.</param>
        public IEnumerable<object> GetServices(Type serviceType)
        {
            return Container.GetAll(serviceType);
        }
    }
}